package threadandrunnable;

public class Runnableexam {
    public static void main(String[] args) {
        MyRunnable m=new MyRunnable();
        new Thread(m,"线程1").start();
        new Thread(m,"线程2").start();
    }
    static class MyRunnable implements Runnable{
        private int ticket=5; //资源
        @Override
        public void run() {
            while(true){
                System.out.println(Thread.currentThread().getName()+"卖票--->"+ ticket--);
                if(ticket < 0){
                    break;
                }
            }
        }
    }
}
